/*
 *  Copyright 2011 Zeta.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package com.oilsoft.scm.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oilsoft.scm.dao.user.UserDAO;
import com.oilsoft.scm.domain.User;

/**
 * 
 * @author Zeta
 */
@Service("userService")
@RemotingDestination(value="userService", channels = { "my-amf" })
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDAO userDAO;

	public UserServiceImpl() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	@RemotingInclude
	public User saveUser(User user) {
		User u = userDAO.merge(user);

		return u;
	}

	@Override
	@RemotingInclude
	public User deleteUser(User user) {
		userDAO.remove(user);
		return user;
	}

	@Override
	@RemotingInclude
	public List<User> getUserList() {
		return userDAO.getAll();
	}

	@Override
	@RemotingInclude
	public User validateUser(String username, String password) {
		return userDAO.validateUser(username, password);
	}

}
